<template>
    <el-dialog
            :title="!dataForm.formatId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="格式设置唯一标识" prop="formatId">
                        <el-input v-model.number="dataForm.formatId" placeholder="格式设置唯一标识"></el-input>
                </el-form-item>
                <el-form-item label="关联的审计报告ID" prop="reportId">
                        <el-input v-model.number="dataForm.reportId" placeholder="关联的审计报告ID"></el-input>
                </el-form-item>
                <el-form-item label="字体" prop="fontFamily">
                        <el-input v-model="dataForm.fontFamily" placeholder="字体"></el-input>
                </el-form-item>
                <el-form-item label="字号" prop="fontSize">
                        <el-input v-model.number="dataForm.fontSize" placeholder="字号"></el-input>
                </el-form-item>
                <el-form-item label="行距" prop="lineSpacing">
                        <el-input v-model="dataForm.lineSpacing" placeholder="行距"></el-input>
                </el-form-item>
                <el-form-item label="页眉页脚内容" prop="headerFooter">
                        <el-input v-model="dataForm.headerFooter" placeholder="页眉页脚内容"></el-input>
                </el-form-item>
                <el-form-item label="图表样式" prop="chartStyle">
                        <el-input v-model="dataForm.chartStyle" placeholder="图表样式"></el-input>
                </el-form-item>
                <el-form-item label="自定义样式" prop="customStyles">
                        <el-input v-model="dataForm.customStyles" placeholder="自定义样式"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            formatId: null,
            reportId: null,
            fontFamily: null,
            fontSize: null,
            lineSpacing: null,
            headerFooter: null,
            chartStyle: null,
            customStyles: null
          },
          dataRule: {
            formatId: [
                        { required: true, message: '格式设置唯一标识不能为空', trigger: 'blur' }
            ],
            reportId: [
                        { required: true, message: '关联的审计报告ID不能为空', trigger: 'blur' }
            ],
            fontFamily: [
                        { required: true, message: '字体不能为空', trigger: 'blur' }
            ],
            fontSize: [
                        { required: true, message: '字号不能为空', trigger: 'blur' }
            ],
            lineSpacing: [
                        { required: true, message: '行距不能为空', trigger: 'blur' }
            ],
            headerFooter: [
                        { required: true, message: '页眉页脚内容不能为空', trigger: 'blur' }
            ],
            chartStyle: [
                        { required: true, message: '图表样式不能为空', trigger: 'blur' }
            ],
            customStyles: [
                        { required: true, message: '自定义样式不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.formatId = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.formatId = id || 0
            if (this.dataForm.formatId) {
              this.$http({
                url: this.$http.adornUrl(`/app/audit_report_format/info/${this.dataForm.formatId}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appauditreportformat
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/audit_report_format/${!this.dataForm.formatId ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>